Ext.define('WorkExperience', {
    extend: 'Ext.data.Model',
    fields: [
        "Id"
		, "StartDate"   //起始日期
		, "EndDate"   //截至日期
		, "WorksFor"   //工作单位
		, "Post"   //岗位
		, "Leader"   //汇报对象
		, "WorkContent"   //工作内容
		, "WorkEvaluate"   //工作评价
		, "Project"   //参与项目
		, "EmpId"   //员工Id
		, "EmpName"   //员工姓名
	],
    idProperty: "Id"
});

Ext.define('SHApp.EmployeeInfo.WorkExperience.Grid', {
    extend: 'BLBTSystem.grid',
    alias: 'shapp.employeeinfo.grid',
    requires: ['SHApp.EmployeeInfo.WorkExperience.Form'],
    txtStartDateID: 'txtStartDate',
    txtEndDateID: 'txtEndDate',
    txtWorksForID: 'txtWorksFor',
    dataModel: "WorkExperience",
    dataUrl: "api/workexperience?format=json",
    empId: "",
    empName: "",
    initComponent: function () {
        var me = this;
        Ext.apply(this);
        me.btnAddID += me.id;
        me.btnEditID += me.id;
        me.btnDeleteID += me.id;
        me.txtStartDateID += me.id;
        me.txtEndDateID += me.id;
        me.txtWorksForID += me.id;
        this.creatTbar();
        this.creatColumns();
        this.callParent(arguments);
        this.checkBtnPermission(me.pvalue);
    },
    creatColumns: function () {
        var me = this;
        me.columns = [
            {
                text: "Id",
                flex: 1,
                dataIndex: 'Id',
                sortable: false,
                hidden: true
            }, {
                text: "起始日期",
                width: 100,
                dataIndex: 'StartDate',
                sortable: true,
                renderer: formatDate
            }, {
                text: "截至日期",
                width: 100,
                dataIndex: 'EndDate',
                sortable: true,
                renderer: formatDate
            }, {
                text: "工作单位",
                width: 100,
                dataIndex: 'WorksFor',
                sortable: true
            }, {
                text: "岗位",
                width: 100,
                dataIndex: 'Post',
                sortable: true
            }, {
                text: "汇报对象",
                width: 100,
                dataIndex: 'Leader',
                sortable: true
            }, {
                text: "工作内容",
                width: 100,
                dataIndex: 'WorkContent',
                sortable: true
            }, {
                text: "工作评价",
                width: 100,
                dataIndex: 'WorkEvaluate',
                sortable: true
            }, {
                text: "参与项目",
                width: 100,
                dataIndex: 'Project',
                sortable: true
            }
        ]
    },
    creatTbar: function () {
        var me = this;
        me.tbar = [
            {
                xtype: 'datefield',
                format: 'Y-m-d',
                fieldLabel: '起始日期:',
                name: 'StartDate',
                value: new Date(),
                id: me.txtStartDateID,
                labelWidth: 60,
                width: 180
            }, {
                xtype: 'datefield',
                format: 'Y-m-d',
                fieldLabel: '截至日期:',
                name: 'EndDate',
                value: new Date(),
                id: me.txtEndDateID,
                labelWidth: 60,
                width: 180
            }, {
                xtype: 'textfield',
                disabled: false,
                fieldLabel: '工作单位:',
                labelWidth: 60,
                name: 'WorksFor',
                id: me.txtWorksForID,
                width: 180
            }, ' ', {
                xtype: 'button',
                text: '查询',
                iconCls: 'icon-btn-search',
                handler: function () {
                    me.clearFilters();
                    me.addFilter("EmpId", me.empId);
                    var vStartDate = me.down("#" + me.txtStartDateID).getValue();
                    vStartDate = getDateString(vStartDate);
                    if (vStartDate && vStartDate.length > 0) {
                        me.addFilter("StartDate", vStartDate);
                    }
                    var vEndDate = me.down("#" + me.txtEndDateID).getValue();
                    vEndDate = getDateString(vEndDate);
                    if (vEndDate && vEndDate.length > 0) {
                        me.addFilter("EndDate", vEndDate);
                    }
                    var vWorksFor = me.down("#" + me.txtWorksForID).getValue();
                    if (vWorksFor && vWorksFor.length > 0) {
                        me.addFilter("WorksFor", vWorksFor);
                    }
                    me.loadByFilter();
                }
            }, '->', {
                xtype: 'button',
                text: '添加',
                id: me.btnAddID,
                iconCls: 'icon-btn-add',
                handler: function () {
                    var win = me.getForm('SHApp.EmployeeInfo.WorkExperience.Form');
                    win.loadRecord(new WorkExperience({ Id: null, EmpId: me.empId, EmpName: me.empName, StartDate: new Date(), EndDate: new Date() }));
                    win.Show("添加");
                }
            }, ' ', {
                xtype: 'button',
                disabled: true,
                id: me.btnEditID,
                text: '修改',
                iconCls: 'icon-btn-edit',
                handler: function () {
                    var rs = me.getSelectionModel().getSelection();
                    if (rs) {
                        if (rs.length > 0) {
                            rs[0].data.StartDate = formatDate(rs[0].data.StartDate);
                            rs[0].data.EndDate = formatDate(rs[0].data.EndDate);
                            me.EditData(me.getForm('SHApp.EmployeeInfo.WorkExperience.Form'));
                        }
                    }
                }
            }, ' ', {
                xtype: 'button',
                disabled: true,
                id: me.btnDeleteID,
                text: '删除',
                iconCls: 'icon-btn-delete',
                handler: function () {
                    me.DeleteData();
                }
            }
        ]
    }
})

